﻿using System;
using System.Windows.Forms;

namespace Amgine
{
    partial class LinkmanDetailsEditForm : Form
    {
        private LinkmanDetails details;

        public LinkmanDetailsEditForm(LinkmanDetails details)
        {
            InitializeComponent();
            this.details = (details == null ? new LinkmanDetails() : details);
        }

        private void LinkmanDetailsEditForm_Load(object sender, EventArgs e)
        {
            comboBox_type.SelectedIndex = details.Type;
            textBox_info.Text = details.Info;
            textBox_remark.Text = details.Remark;
        }

        private void button_confirm_Click(object sender, EventArgs e)
        {
            details.Type = comboBox_type.SelectedIndex;
            details.Info = textBox_info.Text;
            details.Remark = textBox_remark.Text;

            if (validateData())
            {
                if (details.createOrUpdate())
                {
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    DialogResult = DialogResult.Retry;
                }
                Close();
            }
        }

        private bool validateData()
        {
            if (string.IsNullOrWhiteSpace(details.Info))
            {
                MessageBox.Show("值不可为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            if (string.IsNullOrWhiteSpace(details.Remark))
            {
                MessageBox.Show("备注不可为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            return true;
        }

        private void button_cancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }
    }
}
